package qlsl.androiddesign.http.service.subservice;

import java.util.HashMap;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.umeng.socialize.utils.Log;

import qlsl.androiddesign.constant.WhatConstant;
import qlsl.androiddesign.entity.commonentity.Pager;
import qlsl.androiddesign.entity.otherentity.CarDetail;
import qlsl.androiddesign.entity.otherentity.Trailer;
import qlsl.androiddesign.fragment.subfragment.RecruitFragment;
import qlsl.androiddesign.handler.subhandler.HttpHandler;
import qlsl.androiddesign.http.HttpListener;
import qlsl.androiddesign.http.service.baseservice.BaseService;
import qlsl.androiddesign.http.xutils.HttpProtocol;
import qlsl.androiddesign.thread.HandlerThread;
import qlsl.androiddesign.util.commonutil.PagerUtils;
import qlsl.androiddesign.view.baseview.FunctionView;

/**
 * 快拖模块 <br/>
 * 
 */
public class TrailerService extends BaseService {

	private static String className = getClassName(TrailerService.class);

	/**
	 * 快修/快拖店列表
	 * 
	 * @param functionView
	 * @param listener
	 */
	public static void queryQuickLyrepairList(final int page,
			final String servertype, final String longitude,
			final String latitude, final String city, final String type,
			final FunctionView<?> functionView, final HttpListener listener) {
		final HttpHandler handler = getHandler(functionView, listener,
				className, "queryQuickLyrepairList");
		new HandlerThread(className, "queryQuickLyrepairList") {
			public void run() {
				HttpProtocol protocol = new HttpProtocol();
				try {
					JSONObject jo = protocol.setMethod("getquicklyrepairlist")
							.addParam("servertype", servertype)
							.addParam("longitude", longitude)
							.addParam("latitude", latitude)
							.addParam("city", city).addParam("type", type)
							.post();
					if (isDataInvalid(jo, handler, protocol)) {
						return;
					}

					HashMap<String, Object> map = new HashMap<String, Object>();
					List<Trailer> list = JSONArray.parseArray(
							jo.getString("rows"), Trailer.class);
					Pager pager = PagerUtils.createPager(page, jo);
					map.put("list", list);
					map.put("pager", pager);
					// Trailer
					handler.sendMessage(protocol,
							WhatConstant.WHAT_NET_DATA_SUCCESS, map);
				} catch (Exception e) {
					e.printStackTrace();
					handler.sendMessage(protocol, WhatConstant.WHAT_EXCEPITON,
							e);
				}
			};
		}.start();
	}

}
